package com.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.dto.OrderTypeFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyDlxListener {


    @RabbitListener(queues = "q.do.dlx")
    public void onMessage(Message message, Channel channel) throws IOException {

//        System.out.println(new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
        System.out.println("死信队列接受到消息，开始处理死信队列中的消息");
        System.out.println("对数据订单进行处理");
        //对订单进行处理
        OrderTypeFactory.getInstance().setType(2);

        // 消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }


}
